﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using VIBlend.WPF.Controls;

namespace AnonsaiWPF.CSharp.TabControl
{
    /// <summary>
    /// Interaction logic for TabControlOverview.xaml
    /// </summary>
    public partial class TabControlHeaderPositions : Window, IWindow
    {
        public TabControlHeaderPositions()
        {
            InitializeComponent();
        }

        public void DetachContent()
        {
            RemoveLogicalChild(Content);
        }


        public void SetTheme()
        {
        }

        public Grid Root
        {
            get
            {
                return this.RootVisual;
            }
        }

        private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.TabControl == null)
                return;

            if (this.comboBox1 == null)
                return;

            switch (comboBox1.SelectedIndex)
            {
                case 0:
                    this.TabControl.TabAlignment = Dock.Top;

                    for (int i = 0; i < TabControl.Items.Count; i++)
                    {
                        VIBlend.WPF.Controls.TabItem item = TabControl.Items[i] as VIBlend.WPF.Controls.TabItem;

                        if (i == 0)
                        {
                            item.Margin = new Thickness(10, 10, 0, 0);
                        }
                        else
                        {
                            item.Margin = new Thickness(2, 10, 0, 0);
                        }
                    }

                    break;
                case 1:
                    this.TabControl.TabAlignment = Dock.Bottom;
                    for (int i = 0; i < TabControl.Items.Count; i++)
                    {
                        VIBlend.WPF.Controls.TabItem item = TabControl.Items[i] as VIBlend.WPF.Controls.TabItem;

                        if (i == 0)
                        {
                            item.Margin = new Thickness(10, 0, 0, 10);
                        }
                        else
                        {
                            item.Margin = new Thickness(2, 0, 0, 10);
                        }
                    }
                    break;
                case 2:
                    this.TabControl.TabAlignment = Dock.Left;
                    for (int i = 0; i < TabControl.Items.Count; i++)
                    {
                        VIBlend.WPF.Controls.TabItem item = TabControl.Items[i] as VIBlend.WPF.Controls.TabItem;

                        if (i == 0)
                        {
                            item.Margin = new Thickness(10, 10, 0, 0);
                        }
                        else
                        {
                            item.Margin = new Thickness(10, 2, 0, 0);
                        }
                    }
                    break;
                case 3:
                    this.TabControl.TabAlignment = Dock.Right;
                    for (int i = 0; i < TabControl.Items.Count; i++)
                    {
                        VIBlend.WPF.Controls.TabItem item = TabControl.Items[i] as VIBlend.WPF.Controls.TabItem;

                        if (i == 0)
                        {
                            item.Margin = new Thickness(0, 10, 10, 0);
                        }
                        else
                        {
                            item.Margin = new Thickness(0, 2, 10, 0);
                        }
                    }

                    break;
            }
        }

        private void comboBox3_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.TabControl == null)
                return;

            if (this.comboBox3 == null)
                return;

            switch (this.comboBox3.SelectedIndex)
            {
                case 0:
                    foreach (VIBlend.WPF.Controls.TabItem item in this.TabControl.Items)
                    {
                        item.TextImageRelation = TextImageRelation.ImageAboveText;
                    }
                    break;
                case 1:
                    foreach (VIBlend.WPF.Controls.TabItem item in this.TabControl.Items)
                    {
                        item.TextImageRelation = TextImageRelation.TextAboveImage;
                    }
                    break;
                case 2:
                    foreach (VIBlend.WPF.Controls.TabItem item in this.TabControl.Items)
                    {
                        item.TextImageRelation = TextImageRelation.ImageBeforeText;
                    }
                    break;
                case 3:
                    foreach (VIBlend.WPF.Controls.TabItem item in this.TabControl.Items)
                    {
                        item.TextImageRelation = TextImageRelation.TextBeforeImage;
                    }
                    break;
            }
        }

        private void comboBox2_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.TabControl == null)
                return;

            if (this.comboBox2 == null)
                return;

            switch (this.comboBox2.SelectedIndex)
            {
                case 0:
                    this.TabControl.TabOrientation = Orientation.Horizontal;
                    break;
                case 1:
                    this.TabControl.TabOrientation = Orientation.Vertical;
                    break;
            }
        }

        private void comboBox4_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.TabControl == null)
                return;

            if (this.comboBox4 == null)
                return;

            foreach (VIBlend.WPF.Controls.TabItem item in TabControl.Items)
            {
                item.SetCornerRadius(new CornerRadius(this.comboBox4.SelectedIndex));
            }
        }
    }
}
